package com.fz.controller.system;

import com.fz.common.ResponseEntity;
import com.fz.beans.IdBeans;
import com.fz.beans.PageBeans;
import com.fz.dto.system.user.UserAdd;
import com.fz.dto.system.user.UserQuery;
import com.fz.dto.system.user.UserUpd;
import com.fz.service.system.UserService;
import com.fz.vo.system.user.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiSort;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

/**
 * @author : xumj
 * @date : 2021/3/19 15:09
 */
@RestController
@Api(value = "用户管理", tags = "用户管理")
@RequestMapping("/user")
@CrossOrigin
@ApiSort(value = 2)
@SuppressWarnings("unchecked")
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping("/findUserList")
    @ApiOperation(value = "查询用户分页列表")
    @ApiOperationSupport(order = 1)
    public ResponseEntity<UserVo> findUserList(UserQuery userQuery, PageBeans pageBeans) throws Exception {
        return userService.findUserList(pageBeans.getPageNum(), pageBeans.getPageSize(), userQuery);
    }

    @GetMapping("/selectUsersList")
    @ApiOperation(value = "查询用户列表")
    @ApiOperationSupport(order = 2)
    public ResponseEntity<UserVo> selectUsersList(UserQuery userQuery) throws Exception {
        return userService.selectUsersList(userQuery);
    }

    @PostMapping("/saveUser")
    @ApiOperation(value = "新增用户")
    @ApiOperationSupport(order = 3)
    public ResponseEntity saveUser(@RequestBody UserAdd userAdd) throws Exception {
        return userService.saveUser(userAdd);
    }

    @PostMapping("/updateUser")
    @ApiOperation(value = "修改用户")
    @ApiOperationSupport(order = 4)
    public ResponseEntity updateUser(@RequestBody UserUpd userUpd) throws Exception {
        return userService.updateUser(userUpd);
    }

    @PostMapping("/delUser")
    @ApiOperation(value = "删除用户")
    @ApiOperationSupport(order = 5)
    public ResponseEntity delUser(@RequestBody IdBeans idBeans) throws Exception {
        return userService.delUser(idBeans.getIds());
    }
}
